#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	int** M = new int* [N];
	int** W = new int* [N];
	int** _W = new int* [N];                         //男生价值反表
	int* WofM = new int[N];
	int* MofW = new int[N];
	for (int i = 0; i < N; i++) {
		M[i] = new int[N];							 //0代表配对失败过，其他代表女生优先号码
		W[i] = new int[N];
		_W[i] = new int[N];
		WofM[i] = 0;                                 //0代表未配对，其他数字代表女生号码
		MofW[i] = 0;
	}
	int x;
	for(int i = 0;i<N;i++)
		for (int j = 0; j < N; j++) {
			cin >> x;
			M[i][j] = x;
		}
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++) {
			cin >> x;
			W[i][j] = x;
			_W[i][x - 1] = 5 - j;
		}
	int pair = 0;
	while (pair < N) {
		for (int i = 0; i < N; i++) {
			if (WofM[i] == 0) {
				for (int j = 0; j < N; j++) {
					if (M[i][j] != 0) {																				//第i号男生向M[i][j]号求婚
						if (MofW[M[i][j]-1] == 0) {																	//女生单身
							MofW[M[i][j]-1] = i + 1;
							WofM[i] = M[i][j];
							pair++;
						}
						else {																						//女生M[i][j]已有配偶
							if (_W[M[i][j]-1][MofW[M[i][j]-1] - 1] > _W[M[i][j]-1][i]) {							//当前配偶MofW[M[i][j]]价值高
								M[i][j] = 0;
							}
							else{																					//当前男生i价值高
								WofM[i] = M[i][j];
								WofM[MofW[M[i][j]-1] - 1] = 0;
								MofW[M[i][j] - 1] = i + 1;
								for(int k = 0 ;k<N;k++)
									if (M[MofW[M[i][j] - 1] - 1][k] == M[i][j]) {
										M[MofW[M[i][j] - 1] - 1][k] = 0;
										break;
									}
							}
						}
						break;
					}
				}
			}
		}
	}
	for (int i = 0; i < N - 1; i++)
		cout << WofM[i] << " ";
	cout << WofM[N - 1];

	return 0;
}